import { ImageSpec } from "../consts/Assets";
import { EventNames } from "../consts/EventNames";
import Points from "../consts/Points";
import EventBus from "../core/EventBus";
import ScreenManager from "../core/ScreenManager";
import Utils from "../Utils";

export default class FindImageAction extends bt.Action {
    public static create(imgSpec: ImageSpec, withToast: boolean = true): FindImageAction {
        return new FindImageAction(imgSpec, withToast);
    }

    constructor(private imgSpec: ImageSpec, private withToast: boolean = true) {
        super();
    }

    execute(input: bt.BlackBoard): number {

        let points: any[] = images.matchTemplate(ScreenManager.screenshot, this.imgSpec.img, {
            threshold: 0.4,
            region: this.imgSpec.region
        }).points;

        if (points.length > 0) {
            input.content[Points.BT_POINTS] = [points[0].x, points[0].y];
            return bt.State.success;
        }

        if (this.withToast) {
            //toastLog(`找不到图片 ${this.imgSpec.filename}`);
        }
        return bt.State.failure;
    }
}